#include <iostream>
#include <vector>
#include "Computer.h"
#include "Point.h"
#include <limits>
#include "String.h"

using std::istream;
using std::string;
using std::cin;
using std::cout;
using std::endl;
using std::vector;

/***
 * 1. 实现一个单例的Computer类，包含品牌和价格信息。
 */
void test1(){
    Computer::getInstance()->toString();
    cout << Computer::getInstance() << endl;

    Computer::getInstance()->init(8888, "google");
    cout << Computer::getInstance() << endl;
    Computer::getInstance()->toString();

    Computer::destroy();
    Computer::destroy();
}

/***
 * 2. 创建存放Point对象的vector，尝试进行遍历
 */
void test2(){
    Point p1(7, 0);
    Point p2(2, -3);
    Point p3(4, 2);
    Point p4(1, 7);
    Point p5(3, -2);

    vector<Point*> vec1;
    vec1.push_back(&p1);
    vec1.push_back(&p2);
    vec1.push_back(&p3);
    vec1.push_back(&p4);
    vec1.push_back(&p5);

    /* 注意优先级 */
    for(vector<Point*>::iterator it = vec1.begin(); it != vec1.end(); it++){
        (*it)->toString();
    }


}

/***
 * 创建存放“存放int数据的vector”的vector，尝试进行遍历，并体会vector对象和元素的存储位置
 */
void test3(){
    vector<vector<int>> vec;
    vector<int> v1 = {1, 2, 3, 4};
    vector<int> v2 = {1, 2, 3};
    vector<int> v3 = {1, 2};
    vector<int> v4 = {1};

    vec.push_back(v1);
    vec.push_back(v2);
    vec.push_back(v3);
    vec.push_back(v4);

    for(vector<vector<int>>::iterator iterator1 = vec.begin(); iterator1 != vec.end(); iterator1++){
        for(vector<int>::iterator iterator2 = iterator1->begin(); iterator2 != iterator1->end(); iterator2++){
            cout << (*iterator2) << " ";
        }
        cout << endl;
    }

}


/***
 * 流失效时，如何重置流的状态，并重新再正常使用流呢？
 *
 */
void test4(){
    int num;
    cin >> num;
    cout << "num1:" << num << endl;

    if(!cin.good()) {
        cin.clear();
        cin.ignore(0x7fffffffffffffff,'\n');
    }

    string line;
    cin >> line;
    cout << "line:" << line << endl;
}

/**
 * 实现一个自定义的String类，保证main函数对正确执行。
 * 实现时，记得采用增量编写的方式，逐一测试。
 */
void test5(){
    String str1;
//    str1.print();


    String str2 = "Hello,world";/*这里走的是有参构造*/
    String str3("wangdao");

//    str2.print();
//    str3.print();

    String str4 = str3;/*这里走的是拷贝构造*/
//    str4.print();

    str4 = str2;/*这里走的是重载赋值运算符*/
    str4.print();

    cout << &str4 <<endl;
    cout << &str2 <<endl;
    str4 = str4;

    cout << &str4 <<endl;
}


int main(void) {
    test5();
    return 0;
}
